package com.mdlib.helper.model;


import com.mdlib.helper.model.entity.AppFrontInfo;
import com.mdlib.helper.model.entity.AppInitEntity;
import com.mdlib.helper.model.entity.AppLocationEntity;
import com.mdlib.helper.utils.MDAppUtils;
import com.orhanobut.logger.Logger;

import java.io.Serializable;

/**
 * Created by librabin on 16/11/18.
 */

public class AppModel implements Serializable, Cloneable {

    public static final String TAG = "app_object";

    private static final long serialVersionUID = 1L;


    private static AppModel instance;

    private String imageHeader;

    private int versionCode;

    private AppFrontInfo appFrontInfo;

    private AppInitEntity appInitEntity;

    private AppLocationEntity appLocationEntity;

    private String pushToken;

    public static AppModel getInstance() {
        if (instance == null) {
            synchronized (AppModel.class) {
                Object object = MDAppUtils.restoreObject(TAG);
                if (object == null) {
                    object = new AppModel();
                    MDAppUtils.saveObject(TAG, object);
                }

                instance = (AppModel) object;
            }
        }
        return instance;
    }



    public void writeToCache() {
        MDAppUtils.saveObject(TAG, this);
    }

    public void reset() {
        clearData();
        MDAppUtils.saveObject(TAG, this);
    }

    public void clearCache() {
        clearData();
        MDAppUtils.saveObject(TAG, this);
    }

    private void clearData() {
        imageHeader = null;
        appFrontInfo = null;
        appInitEntity = null;
        appLocationEntity=null;
        pushToken = null;

    }
    public String getPushToken() {
        Logger.e("cid: " + pushToken);
        return pushToken;
    }

    public void setPushToken(String pushCid) {
        this.pushToken = pushCid;
    }


    public AppFrontInfo getAppFrontInfo() {
        return appFrontInfo;
    }

    public void setAppFrontInfo(AppFrontInfo appFrontInfo) {
        this.appFrontInfo = appFrontInfo;
    }

    public AppInitEntity getAppInitEntity() {
        return appInitEntity;
    }

    public void setAppInitEntity(AppInitEntity appInitEntity) {
        this.appInitEntity = appInitEntity;
    }

    public AppLocationEntity getAppLocationEntity() {
        return appLocationEntity;
    }

    public void setAppLocationEntity(AppLocationEntity appLocationEntity) {
        this.appLocationEntity = appLocationEntity;
    }
}
